﻿using System;
using CPN.PJN.Silverlight.Common.Configuration;
using CPN.PJN.Silverlight.Common.Logging;
using CPN.PJN.Silverlight.Common.Logging.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CPN.PJN.Common.Logging.UnitTests
{
    [TestClass]
    public class Tests
    {
        public Uri ConfigurationUri
        {
            get
            {
                return new Uri(@"http://localhost:8888/clientbin/Silverlight.Core.xml", UriKind.RelativeOrAbsolute);
            }
        }

        [TestMethod]
        public void TestMethod1_LoggerConfigurationManager()
        {
            ConfigurationManager.Instance.ConfigurationFilename = this.ConfigurationUri;
            ConfigurationManager.Instance.ConfigurationDownloadCompleted += (s,e)=>
            {
                // Configuration du Logger
                LoggerConfigurationManager.Instance.Configure();

                // Véirife que la configuration comporte plus d'une catégorie
                Assert.IsTrue(LoggerConfigurationManager.Instance.LogCategoryDictionary.Count > 0);
            };
            ConfigurationManager.Instance.DownloadConfiguration();
        }

        [TestMethod]
        public void TestMethod2_LoggerWrite()
        {
            ConfigurationManager.Instance.ConfigurationFilename = this.ConfigurationUri;
            ConfigurationManager.Instance.ConfigurationDownloadCompleted += (s, e) =>
            {
                // Configuration du Logger
                LoggerConfigurationManager.Instance.Configure();

                // Vérifie l'Exécution
                Logger.Instance.Write("Silverlight Log me !");
                Logger.Instance.Write("Silverlight Log Info !", Logger.DEFAULT_CATEGORY, LogSeverity.Information);
                Logger.Instance.Write("Silverlight Log Debug !", Logger.DEFAULT_CATEGORY, LogSeverity.Verbose);
                Logger.Instance.Write("Silverlight Log Erreur !", Logger.DEFAULT_CATEGORY, LogSeverity.Error);
                Logger.Instance.Write("Silverlight Log Fatal !", Logger.DEFAULT_CATEGORY, LogSeverity.Critical);
                Logger.Instance.Write("Silverlight Log Info !", Logger.DEFAULT_CATEGORY, LogSeverity.Information, "value1", 100);
            };
            ConfigurationManager.Instance.DownloadConfiguration();
        }

    }
}